package com.thitech.sif.context;

import java.util.ArrayList;
import java.util.List;

import com.thitech.sif.interceptor.InterceptorHandler;
import com.thitech.sif.utils.secutiry.EncryptUtils;

/**
 * 服务调用时需要信息的上下文对象
 * 
 * @author shisheng.lian
 * 
 */
public abstract class AbsContext {

	/**
	 * 服务系统名称
	 */
	private String systemName;

	/**
	 * 服务名称
	 */
	private String serviceName;

	/**
	 * 服务系统主机名或IP地址
	 */
	private String host;

	/**
	 * 服务系统服务端口
	 */
	private int port = -1;

	/**
	 * 服务连接超时时间，单位：毫秒，默认1分钟
	 */
	private int cto = 60000;

	/**
	 * 服务读取超时时间，单位：毫秒，默认1分钟
	 */
	private int rto = 60000;

	/**
	 * 服务系统字符集编码，不设置默认为utf-8
	 */
	private String charset = "UTF-8";

	/**
	 * 服务对应拦截器链，初始化时把默认拦截器也植入该集合中
	 */
	private List<InterceptorHandler> interceptors;

	/**
	 * 安全校验用户名
	 */
	private String userName;

	/**
	 * 安全校验密码
	 */
	private String password;

	/**
	 * 返回值判断类全限定名
	 */
	private String returnAssertClass;

	public String getSystemName() {
		return systemName;
	}

	public void setSystemName(String systemName) {
		this.systemName = systemName;
	}

	public String getServiceName() {
		return serviceName;
	}

	public void setServiceName(String serviceName) {
		this.serviceName = serviceName;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}
	
	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public int getCto() {
		return cto;
	}

	public void setCto(int cto) {
		this.cto = cto;
	}

	public int getRto() {
		return rto;
	}

	public void setRto(int rto) {
		this.rto = rto;
	}

	public String getCharset() {
		return charset;
	}

	public void setCharset(String charset) {
		this.charset = charset;
	}

	public List<InterceptorHandler> getInterceptors() {
		if (null == interceptors) {
			interceptors = new ArrayList<InterceptorHandler>();
		}
		return interceptors;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		userName = EncryptUtils.decryptSensitivity(userName);
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		password = EncryptUtils.decryptSensitivity(password);
		this.password = password;
	}


	public String getReturnAssertClass() {
		return returnAssertClass;
	}

	public void setReturnAssertClass(String returnAssertClass) {
		this.returnAssertClass = returnAssertClass;
	}

	/**
	 * 由子类实现，获取服务类型，通过SLogFactory取值
	 */
	public abstract String getServiceType();
}
